package com.hq.fxh.CustomerView;

import android.os.CountDownTimer;
import android.widget.TextView;

import com.hq.fxh.R;


/**
 * 计时器
 * Created by 大圣  on 2015/7/28 0028.
 */
public class TimeCount extends CountDownTimer {

    private TextView tv;


    public TimeCount(long millisInFuture, long countDownInterval, TextView tv) {
        super(millisInFuture, countDownInterval);
        this.tv = tv;
    }

    /**
     * @param millisInFuture    总时长
     * @param countDownInterval 时间间隔
     */
    public TimeCount(long millisInFuture, long countDownInterval) {
        super(millisInFuture, countDownInterval);
    }

    /**
     * 计时过程显示
     *
     * @see CountDownTimer#onTick(long)
     */
    @Override
    public void onTick(long millisUntilFinished) {
        tv.setClickable(false);
        tv.setSelected(true);
        tv.setText("获取验证码 " + millisUntilFinished / 1000);

    }

    /**
     * 计时完成时触发
     *
     * @see CountDownTimer#onFinish()
     */
    @Override
    public void onFinish() {
        cancel();
        tv.setText(R.string.re_send_message_code);
        tv.setSelected(false);
        tv.setClickable(true);
    }
}
